package org.jeecg.basic.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.basic.entity.MesLineCfg;
import org.jeecg.basic.service.IMesLineCfgService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Description: 产线配置
 * @Author: LiCY
 * @Date: 2023-06-14
 * @Version: V1.0
 */
@Api(tags = "产线配置")
@RestController
@RequestMapping("/basic/mesLineCfg")
@Slf4j
public class MesLineCfgController extends JeecgController<MesLineCfg, IMesLineCfgService> {
    @Autowired
    private IMesLineCfgService mesLineCfgService;


    /**
     * 分页列表查询
     *
     * @param mesLineCfg
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "产线配置-分页列表查询")
    @ApiOperation(value = "产线配置-分页列表查询", notes = "产线配置-分页列表查询")
    @GetMapping(value = "/list")
    @DS("history")
    public Result<IPage<MesLineCfg>> queryPageList(MesLineCfg mesLineCfg,
                                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                   HttpServletRequest req) {
        QueryWrapper<MesLineCfg> queryWrapper = QueryGenerator.initQueryWrapper(mesLineCfg, req.getParameterMap());
        Page<MesLineCfg> page = new Page<MesLineCfg>(pageNo, pageSize);
        IPage<MesLineCfg> pageList = mesLineCfgService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param mesLineCfg
     * @return
     */
    @AutoLog(value = "产线配置-添加")
    @ApiOperation(value = "产线配置-添加", notes = "产线配置-添加")
    //@RequiresPermissions("org.jeecg.basic.demo:mes_line_cfg:add")
    @PostMapping(value = "/add")
    @DS("business")
    public Result<String> add(@RequestBody MesLineCfg mesLineCfg) {
        mesLineCfgService.save(mesLineCfg);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param mesLineCfg
     * @return
     */
    @AutoLog(value = "产线配置-编辑")
    @ApiOperation(value = "产线配置-编辑", notes = "产线配置-编辑")
    //@RequiresPermissions("org.jeecg.basic.demo:mes_line_cfg:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    @DS("business")
    public Result<String> edit(@RequestBody MesLineCfg mesLineCfg) {
        mesLineCfgService.updateById(mesLineCfg);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param mesLineCfg
     * @return
     */
    @AutoLog(value = "产线配置-通过id删除")
    @ApiOperation(value = "产线配置-通过id删除", notes = "产线配置-通过id删除")
    //@RequiresPermissions("org.jeecg.basic.demo:mes_line_cfg:delete")
    @RequestMapping(value = "/delete")
    public Result<String> delete(@RequestBody MesLineCfg mesLineCfg) {
        mesLineCfgService.removeById(mesLineCfg);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param list
     * @return
     */
    @AutoLog(value = "产线配置-批量删除")
    @ApiOperation(value = "产线配置-批量删除", notes = "产线配置-批量删除")
    //@RequiresPermissions("org.jeecg.basic.demo:mes_line_cfg:deleteBatch")
    @RequestMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestBody List<MesLineCfg> list) {
        list.forEach(item -> {
            mesLineCfgService.removeById(item);
        });
        //this.mesLineCfgService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "产线配置-通过id查询")
    @ApiOperation(value = "产线配置-通过id查询", notes = "产线配置-通过id查询")
    @GetMapping(value = "/queryById")
    @DS("business")
    public Result<MesLineCfg> queryById(@RequestParam(name = "id", required = true) String id) {
        MesLineCfg mesLineCfg = mesLineCfgService.getById(id);
        if (mesLineCfg == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(mesLineCfg);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param mesLineCfg
     */
    //@RequiresPermissions("org.jeecg.basic.demo:mes_line_cfg:exportXls")
    @RequestMapping(value = "/exportXls")
    @DS("history")
    public ModelAndView exportXls(HttpServletRequest request, MesLineCfg mesLineCfg) {
        return super.exportXls(request, mesLineCfg, MesLineCfg.class, "产线配置");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    //@RequiresPermissions("mes_line_cfg:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    @DS("business")
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, MesLineCfg.class);
    }

}
